package com.zxhysy.log.annotation.context;

import com.zxhysy.log.annotation.LogIgnore;
import com.zxhysy.log.annotation.advisor.LogIgnoreParser;
import lombok.Data;
import org.springframework.aop.framework.AopProxyUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

/**
 * 方法参数
 * @author zhangxinhong
 * @since 2022/1/28 10:06
 */
@Data
public class MethodParameter {

    /**
     * 调用类
     */
    private Object target;

    /**
     * 参数
     */
    private Object[] args;

    /**
     * 目标类
     */
    private Class<?> targetClass;

    /**
     * 方法
     */
    private Method method;

    public MethodParameter(Object target, Method method, Object[] arguments) {
        this.args = arguments;
        this.method = method;
        this.target = target;
        this.targetClass = AopProxyUtils.ultimateTargetClass(target);
    }

    /**
     * 方法参数忽略
     *
     * @return 入参忽略坐标
     */
    public Set<Integer> methodParamsIndexIgnore() {
        return LogIgnoreParser.methodParamsIndexIgnore(this.method);
    }
}
